Skip to content

Conversation

@moodysalem
Copy link
Member

No description provided.

@mentatbot
Copy link
Contributor

mentatbot bot commented Jun 9, 2025

I'm getting to work. See my steps and track my cost here.

  • Wake on any new activity.
    I always see new activity while actively working. When paused, I'll only respond when tagged unless this box is checked. Learn more about triggers.

@moodysalem moodysalem merged commit b6b7216 into main Jun 9, 2025
1 check passed
@moodysalem moodysalem deleted the mev-resist branch June 9, 2025 21:46
@mentatbot
Copy link
Contributor

mentatbot bot commented Jun 9, 2025

This PR implements an MEV-resistant pool that charges additional fees based on price movement during swaps. The core concept is solid - larger price movements incur higher fees to discourage MEV attacks. Here are my findings from testing and code review:

✅ What Works Well

  • Tests pass: All existing tests continue to pass, and the new MEV resist pool tests work correctly
  • Clean architecture: The wrapper pattern around BasePool is well-designed
  • Path dependency tracking: Good addition of is_path_dependent() to distinguish pools where swap order matters

🔍 Areas for Improvement

1. Precision Concerns in u256_to_float_base_x128()

The new function converts U256 to f64, which could lose precision for large values:

pub fn u256_to_float_base_x128(x128: U256) -> f64 {
    x128.0[0] as f64 / 340282366920938463463374607431768211456f64
        + (x128.0[1] as f64 / 18446744073709551616f64)
        + x128.0[2] as f64
        + (x128.0[3] as f64 * 18446744073709551616f64)
}

f64 has ~15-17 decimal digits of precision, but U256 can represent much larger numbers. Consider documenting the precision limitations or using a more precise approach for critical calculations.

2. Duplicate Constants

You now have two related constants in different files:

  • SQRT_TICK_SIZE = 1.00000049999987500006249996093752734372949220361326815796989439990616646 (tick.rs)
  • LOG_BASE_SQRT_TICK_SIZE = 4.9999975000016666654...e-7 (util.rs)

These represent the same mathematical relationship (log(SQRT_TICK_SIZE)). Consider consolidating to avoid potential drift and make maintenance easier.

3. Clippy Warnings

The build shows several clippy warnings that should be addressed:

  • Excessive precision in float constants
  • Unnecessary map_or usage
  • Useless conversions

Running cargo clippy --fix would clean these up.

4. Missing Documentation

The new public functions lack documentation comments. Consider adding docs for:

  • approximate_sqrt_ratio_to_tick()
  • u256_to_float_base_x128()
  • The MEV resist pool validation logic

🧪 Testing Results

$ cargo test mev_resist
running 2 tests
test quoting::mev_resist_pool::tests::test_swap_output_amount_token0 ... ok
test quoting::mev_resist_pool::tests::test_swap_input_amount_token0 ... ok

The tests demonstrate the additional fee calculation working correctly for both exact input and exact output scenarios.

Overall this is a solid implementation of an interesting MEV resistance mechanism. The issues I've identified are mostly around code quality and maintainability rather than functional correctness.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants